﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerInfo : MonoBehaviour {

    public Text playerName;
    public Text playerHealth;
    public Scrollbar playerHealthBar;

    private int _maxHealth = 100;
    private int _currenHealth = 100;

    public int CurrenHealth
    {
        get { return _currenHealth; }
        set { _currenHealth = value; }
    }

	// Use this for initialization
	void Start () {
        playerName.text = "但丁";
        playerHealth.text = _currenHealth + " / " + _maxHealth;
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void SetHealth(int damage)
    {
        _currenHealth += damage;

        if (_currenHealth > _maxHealth)
        {
            _currenHealth = _maxHealth;
        }

        float pro = ((float)_currenHealth / _maxHealth);

        playerHealthBar.size = pro;

        playerHealth.text = _currenHealth + " / " + _maxHealth;

        if (_currenHealth <= 0)
        {
            ScrollRectControl.Instance.TheEnd();
        }
    }
}
